<?php
/**
 * 适配器模式经常和工厂模式一起使用
 */

namespace App\DesignPattern\Adapter;

use App\DesignPattern\Adapter\DbMysql;
use App\DesignPattern\Adapter\DbMysqli;
use App\DesignPattern\Adapter\DbPdo;

class DbFactory {

	/**
	 * DB工厂，返回DB实例
     * @param string $_db_type 返回的DB类型
     * @return DbMysql|DbMysqli|DbPdo|null
     */
	public static function create($_db_type = 'mysql'){
		switch(strtolower($_db_type)){
            case 'mysql':
                return new DbMysql('127.0.0.1', 'root', '123456', 'gm_test');
            case 'mysqli':
                return new DbMysqli('127.0.0.1', 'root', '123456', 'gm_test');
			case 'pdo':
				return new DbPdo('127.0.0.1', 'root', '123456', 'gm_test');
			default :
				return null;
		}
	}
}
